﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A2DFramework.LockService.Providers
{
    public class RedisLockProvider : ILockProvider
    {
        public IDisposable AcquireLock(string lockName, TimeSpan timeout)
        {
            using(var redis=RedisFactory.GetRedisClient())
            {
                if(timeout==TimeSpan.Zero||timeout==TimeSpan.MaxValue)
                    return redis.AcquireLock(lockName);
                else
                    return redis.AcquireLock(lockName, timeout);
            }
        }

        public void ReleaseLock(IDisposable lockObj )
        {
            if (lockObj != null)
                lockObj.Dispose();
        }
    }
}
